package cn.dubito.manager.service;

import cn.dubito.api.event.ProductStatusEvent;
import cn.dubito.entity.enums.ProductStatusEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @author liliang
 * @description: 产品状态管理
 * @date 2018/5/29.
 */
@Component
public class ProductStatusManager {

    private static final String MQ_DESTINATION = "VirtualTopic.PRODUCT_STATUS";
    private static Logger LOG = LoggerFactory.getLogger(ProductStatusManager.class);

    @Autowired
    private JmsTemplate jmsTemplate;

    /**
     * 消息服务发送
     *
     * @param id
     * @param status
     */
    public void changeStatus(String id, ProductStatusEnum status) {
        ProductStatusEvent event = new ProductStatusEvent(id, status);
        LOG.info("send message: {}", event);
        jmsTemplate.convertAndSend(MQ_DESTINATION, event);
    }

}
